package com.lbssoft.gpsbd.dao;

import com.lbssoft.gpsbd.dao.sql.DeviceSql;
import com.lbssoft.gpsbd.dao.sql.LayerSql;
import com.lbssoft.gpsbd.model.Layer;
import com.lbssoft.gpsbd.model.LayerPermission;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LayerMapper {


	/**
	 * 获取自定义图层
	 * @return
     */
	@Select("SELECT t.* FROM lbs_layers t LEFT JOIN lbs_user_layer a ON a.layerId = t.id LEFT JOIN lbs_users b ON b.id = a.userId  WHERE b.id = #{userId}")
	List<Layer> list(@Param("userId") long userId);

	/**
	 * 更新图层位置
     */
	@UpdateProvider(type = LayerSql.class, method = "update")
	void update(Layer layer);

	/**
	 * 创建图层
	 * @param layer
     */
	@Insert("INSERT INTO lbs_layers(name,url,width,height,coord,visible) VALUE(#{name},#{url},#{width},#{height},#{coord},#{visible})")
	@Options(useGeneratedKeys=true, keyProperty="id")
	void add(Layer layer);

	/**
	 * 创建用户图层关系
	 * @param layerPermission
     */
	@Insert("INSERT INTO lbs_user_layer(userId,layerId) VALUES(#{userId},#{layerId})")
	void addUserLayer(LayerPermission layerPermission);

	/**
	 * 删除图层
	 * @param id
     */
	@Delete("DELETE FROM lbs_layers WHERE id = #{id}")
	void delete(@Param("id") int id);

}
